//
//  BLEManager.h
//  KiWiPeniOSProject
//
//  Created by 曾威林 on 2017/8/27.
//  Copyright © 2017年 zjy. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>

typedef void(^BLESearchBlock)(BOOL, NSArray<CBPeripheral *> *);//搜索相关的
typedef void(^BLEConnectBlock)(BOOL);//连接相关处理
typedef void(^BLEReceiveDataBlock)(NSData *);//处理接收到消息

@interface BLEManager : NSObject

+ (instancetype)shareBLEManager;
- (void)getMatchedPeripheralsWithSearchBlock:(BLESearchBlock)bleSearchBlock;//获取已经配对过的设备
- (void)scanPeripheralsWithName:(NSString *) nameStr AndSearchBlock:(BLESearchBlock)bleSearchBlock;//扫描设备
- (void)connectWithPeripheral:(CBPeripheral *)peripheral AndConnectBlock:(BLEConnectBlock)bleConnectBlock AndReceiveBlock:(BLEReceiveDataBlock)bleReceiveDataBlock;//连接设备
- (void)writeDataWithData:(NSData *)data;//发送数据给蓝牙
- (void)readData;//主动从蓝牙设备读取数据
- (void)cancelAll;//取消扫描，断开连接


//缓存设备的UUID -- 添加设备
- (void) saveConnectedPeripheralWithUUID:(NSString *) uuidStr;

//删除缓存的设备UUID -- 删除设备
- (void) deleteConnectedPeripheralWithUUID:(NSString *) uuidStr;

@end
